home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / compat / protected.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  3.7 KB  |  134 lines  |  [TEXT/ttxt]

  1. /* 
  2.  * protected.c - this file implements four standard system calls
  3.  * with wrappers that ignore interrupts.  The definitions, and
  4.  * the code that uses them, was taken from tcl-7.3.
  5.  *
  6.  * tclUnixUtil.c --
  7.  *
  8.  *    This file contains a collection of utility procedures that
  9.  *    are present in the Tcl's UNIX core but not in the generic
  10.  *    core.  For example, they do file manipulation and process
  11.  *    manipulation.
  12.  *
  13.  *    Parts of this file are based on code contributed by Karl
  14.  *    Lehenbauer, Mark Diekhans and Peter da Silva.
  15.  *
  16.  * Copyright (c) 1991-1993 The Regents of the University of California.
  17.  * All rights reserved.
  18.  *
  19.  * Permission is hereby granted, without written agreement and without
  20.  * license or royalty fees, to use, copy, modify, and distribute this
  21.  * software and its documentation for any purpose, provided that the
  22.  * above copyright notice and the following two paragraphs appear in
  23.  * all copies of this software.
  24.  * 
  25.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  26.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  27.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  28.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  31.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  32.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  33.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  34.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  35.  */
  36.  
  37. #include "std-c.h"
  38. #include "std-os.h"
  39.  
  40. /*
  41.  *----------------------------------------------------------------------
  42.  *
  43.  * protect_open, protect_read, protect_waitpid, and protect_write --
  44.  *
  45.  *    Below are a bunch of procedures that are used instead
  46.  *    of system calls.  Each of the procedures executes the
  47.  *    corresponding system call and retries automatically
  48.  *    if the system call was interrupted by a signal.
  49.  *
  50.  * Results:
  51.  *    Whatever the system call would normally return.
  52.  *
  53.  * Side effects:
  54.  *    Whatever the system call would normally do.
  55.  *
  56.  * NOTE:
  57.  *    This should be the last page of this file, since it undefines
  58.  *    the macros that redirect read etc. to the procedures below.
  59.  *
  60.  *----------------------------------------------------------------------
  61.  */
  62.  
  63. #undef open
  64. int protect_open(path, oflag, mode)
  65.     char *path;
  66.     int oflag;
  67.     int mode;
  68. {
  69.     int result;
  70.     while (1) {
  71.     result = open(path, oflag, mode);
  72.     if ((result != -1) || (errno != EINTR)) {
  73.         return result;
  74.     }
  75.     }
  76. }
  77.  
  78. #undef read
  79. int protect_read(fd, buf, numBytes)
  80.     int fd;
  81.     VOID *buf;
  82.     size_t numBytes;
  83. {
  84.     int result;
  85.     while (1) {
  86.     result = read(fd, buf, (size_t) numBytes);
  87.     if ((result != -1) || (errno != EINTR)) {
  88.         return result;
  89.     }
  90.     }
  91. }
  92.  
  93. #undef waitpid
  94. extern pid_t waitpid _ANSI_ARGS_((pid_t pid, int *stat_loc, int options));
  95.  
  96. /*
  97.  * Note:  the #ifdef below is needed to avoid compiler errors on systems
  98.  * that have ANSI compilers and also define pid_t to be short.  The
  99.  * problem is a complex one having to do with argument type promotion.
  100.  */
  101.  
  102. #ifdef _USING_PROTOTYPES_
  103. int protect_waitpid _ANSI_ARGS_((pid_t pid, int *statPtr, int options))
  104. #else
  105. int protect_waitpid(pid, statPtr, options)
  106.     pid_t pid;
  107.     int *statPtr;
  108.     int options;
  109. #endif /* _USING_PROTOTYPES_ */
  110. {
  111.     int result;
  112.     while (1) {
  113.     result = waitpid(pid, statPtr, options);
  114.     if ((result != -1) || (errno != EINTR)) {
  115.         return result;
  116.     }
  117.     }
  118. }
  119.  
  120. #undef write
  121. int protect_write(fd, buf, numBytes)
  122.     int fd;
  123.     VOID *buf;
  124.     size_t numBytes;
  125. {
  126.     int result;
  127.     while (1) {
  128.     result = write(fd, buf, (size_t) numBytes);
  129.     if ((result != -1) || (errno != EINTR)) {
  130.         return result;
  131.     }
  132.     }
  133. }
  134.